package com.ld.security.server.user.modules.ups.vo;

import com.ld.security.common.core.base.SuperVo;
import com.ld.security.common.mybatis.anno.GroupKey;
import com.ld.security.common.mybatis.anno.QueryKey;
import com.ld.security.common.mybatis.anno.SaveKey;
import com.ld.security.common.mybatis.anno.SqlKey;
import com.ld.security.server.user.modules.ups.constant.UpsKeywordConstant;
import com.ld.security.server.user.modules.ups.entity.UpsKeywordEntity;
import lombok.Data;

import java.util.List;
import java.util.Map;

@Data
public class KeywordDetailsVo implements SuperVo {

    private String upsUserId;


    @SaveKey
    @QueryKey
    @SqlKey(name = "upsUserId", valueField = "upsUserId")
    private List<UpsKeywordEntity> keywordList;

    /**
     * 权重变化
     * @param wt
     * @return
     */
  public KeywordDetailsVo changeWt(double changeWt) {
    for (UpsKeywordEntity keywordEntity : keywordList) {
        double wt =  keywordEntity.getWt() * changeWt;
        int v = (int)wt;
        keywordEntity.setWt(v);
    }
    return this;
  }

        public KeywordDetailsVo addKeyword(UpsKeywordEntity key){
        for (UpsKeywordEntity e : keywordList) {
          if(e.getWtType() == key.getWtType()
                  && e.getKeyword().equals(key.getKeyword()))
                  {

                  //权重增加
                  e.setWt(e.getWt()+key.getWtType().wt);
                  return this;


          }
        }

        //初始化权重
        key.setWt(key.getWtType().wt);
        keywordList.add(key);
        return this;
    }
}
